{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #嵌套函数\n",
    "# def func1():\n",
    "#     print('func1')\n",
    "#     def func2():\n",
    "#         print('func2')\n",
    "#     func2()\n",
    "# func1()#输出func1 func2\n",
    "# #全局变量\n",
    "# a=100\n",
    "# def func3():\n",
    "#     print(a)#输出100\n",
    "# def func4(): #局部变量\n",
    "#     a=200\n",
    "#     print(a)#输出200\n",
    "# def func5():\n",
    "#     global a #修改全局变量a\n",
    "#     global b #定义全局变量b\n",
    "#     b=100\n",
    "#     a=300\n",
    "#     print(a)#输出300\n",
    "# func3()#输出100 \n",
    "# func4()#200\n",
    "# func5()#300\n",
    "# func3()#300\n",
    "# print(b)#100\n",
    "# a=100\n",
    "# def func1():\n",
    "#     a=200\n",
    "#     def func2():\n",
    "#         print('func2',a)#输出200\n",
    "#     func2()\n",
    "#     print('func1',a)#输出func1 200\n",
    "# func1()#输出 func2 200 func1 200 \n",
    "# #lamda表达式  匿名函数\n",
    "# add=lambda a,b:a+b\n",
    "# print(add(1,2))#输出3   \n",
    "# conp=lambda a,b:'a>b' if a>b else 'a<b'\n",
    "# print(conp(1,2))#输出a<b\n",
    "#zip()函数  zip(*iterables)  *iterables表示可迭代对象，返回一个迭代器，迭代器中每个元素都是一个元组，元组中的元素是iterables中相应位置的元素\n",
    "# list1=[1,2,3,4,5]\n",
    "# list2=['a','b','c','d']\n",
    "# list3=list(zip(list1,list2))\n",
    "# print(list3)#[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')] 元素不一致时，取最短的\n",
    "# print(list(zip(*list3)))#[(1, 2, 3, 4), ('a', 'b', 'c', 'd')] 元组解压 转换成列表\n",
    "# #map(func,*iterables)\n",
    "# list1=[1,2,3,4,5]\n",
    "# list2=['a','b','c','d']\n",
    "# list3=list(map(lambda a,b:str(a)+b,list1,list2))\n",
    "# print(list3)#    ['1a', '2b', '3c', '4d']  元素不一致时，取最短的\n",
    "#拆包：\n",
    "# tua=(1,2,3)\n",
    "# a,b,c=tua\n",
    "# print(a,b,c)#1 2 3\n",
    "# a,*c=tua\n",
    "# print(a,c)#1 [2, 3]  *c表示将tua中除了a以外的元素都赋值给c\n",
    "# def func1(a,*b):\n",
    "#     print(a,b)\n",
    "# func1(1,2,3,4,5)#1 (2, 3, 4, 5)  *b表示将func1中除了a以外的参数都赋值给b\n",
    "#异常\n",
    "# a=100\n",
    "# try:\n",
    "#     print(a)\n",
    "# except Exception as e:\n",
    "#     print(e)\n",
    "# else:\n",
    "#     print(\"没有异常才会执行else\")\n",
    "# finally:\n",
    "#     print(\"不管有没有异常都会执行finally\")\n",
    "# 模块 每个py文件都是一个模块  模块名就是文件名 pip install 模块名\n",
    "# 注意：模块名不要和系统模块名冲突，否则将无法导入系统模块\n",
    "# import 模块名\n",
    "# from 模块名 import 函数名1,函数名2\n",
    "# from 模块名 import *  #导入模块中所有函数\n",
    "# from 模块名 import 函数名1 as 函数名2  #函数名2是函数名1的别名\n",
    "#内置全局变量 __name__  文件在当前运行时，__name__的值为__main__  ；  文件被导入时，__name__的值为模块名\n",
    "import basename\n",
    "basename.test()\n",
    "# 输 出\n",
    "# basename.py\n",
    "# basename.py is being imported into another module\n",
    "# test"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
